package com.jiang.daily.Q1399;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/04/23 17:28
 */
class Solution {
    public int countLargestGroup(int n) {
        int[] cnt = new int[37]; // cnt[i] 表示数位和为i的个数
        int res = 0, max = 0;
        for (int i = 1; i <= n; i++) {
            int t = 0; //
            for (int x = i; x > 0; x /= 10) {
                t += x % 10;
            }
            cnt[t]++;
            if (max < cnt[t]) {
                max = cnt[t];
                res = 1;
            } else if (max == cnt[t]) {
                res++;
            }
        }
        return res;
    }
}
